import 'package:get/get.dart';
import 'package:xinxuan/common/dialogs/message_dialog.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/controllers/my_controller/blind_box_order_controller/blind_box_order_page_controller.dart';
import 'package:xinxuan/http/http_util_service.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:xinxuan/vo/blindbox/blind_box_order_detail_vo.dart';
import 'package:xinxuan/vo/msg_vo.dart';

class BlindBoxOrderDetailSuccessPageController extends GetxController {
  
  final CommonPageController commonPageController = Get.find();

  final BlindBoxOrderPageController blindBoxOrderPageController = Get.put(BlindBoxOrderPageController());
  
  var appBarTitle = '订单详情'.obs;
  var orderId = 0.obs;

  var orderDetailData = BlindBoxOrderDetailData(id: 0, status: 0, voucherCode: '', transfer: []).obs;

  @override
  void onInit() {
    Map<String, dynamic> argumentsMap = Get.arguments;
    orderId.value = argumentsMap['id'];
    appBarTitle.value = argumentsMap['title'];
    update();
    super.onInit();
  }

  @override
  void onReady() {
    getBlindBoxOrderDetail();
    super.onReady();
  }

  /// 获取订单详情
  getBlindBoxOrderDetail({bool showLoading = true}) async {
    BlindBoxOrderDetailVo blindBoxOrderDetailVo = await HttpUtilService.getBlindBoxOrderDetail(orderId: orderId.value, loading: showLoading);
    orderDetailData.value = blindBoxOrderDetailVo.data!;
    appBarTitle.value = orderDetailData.value.statusStr ?? '';
    update();
  }

  /// 核销
  Future<bool> checkoff(int orderId) async {
    MsgVo? msgVo = await HttpUtilService.checkoff(id: orderId);
    if (msgVo != null) {
      Get.dialog(MessageDialog(
        message: msgVo.data!.msg ?? '提示异常', 
        title: '提示信息',
        messageColor: textSubtitleColor,
      ));
      return false;
    } else {
      getBlindBoxOrderDetail();
      return true;
    }
  }
  
}